
#include "NodeParamDialog.h"
#include <QtGui/QApplication>
#include "Node.h"


//-------------------------------------

NodeParamDialog::NodeParamDialog( Node * n, QWidget *parent ) :
    QDialog(parent),
    node( 0 )
{
    node = n;

    resize( 540, 260 );
    buttonBox = new QDialogButtonBox( this );
    buttonBox->setGeometry( QRect( 350, 220, 161, 30 ) );
    buttonBox->setOrientation( Qt::Horizontal );
    buttonBox->setStandardButtons( QDialogButtonBox::Cancel | QDialogButtonBox::Ok );
    groupBox = new QGroupBox( this );
    groupBox->setGeometry( QRect( 10, 0, 520, 210 ) );
    widget = new QWidget( groupBox );
    widget->setGeometry( QRect( 10, 20, 500, 180 ) );
    glay = new QGridLayout( widget );
    glay->setContentsMargins( 0, 0, 0, 0 );
    lbl1 = new QLabel( widget );
    glay->addWidget( lbl1, 0, 0, 1, 1 );
    ledtID = new QLineEdit( widget );
    glay->addWidget( ledtID, 0, 1, 1, 1 );
    lbl8 = new QLabel( widget );
    glay->addWidget( lbl8, 0, 2, 1, 1 );
    ledtUmod = new QLineEdit( widget );
    glay->addWidget( ledtUmod, 0, 3, 1, 1 );
    lbl15 = new QLabel( widget );
    glay->addWidget( lbl15, 0, 4, 1, 1 );
    ledtUmax = new QLineEdit( widget );
    glay->addWidget( ledtUmax, 0, 5, 1, 1 );
    lbl2 = new QLabel( widget );
    glay->addWidget( lbl2, 1, 0, 1, 1 );
    ledtName = new QLineEdit( widget );
    glay->addWidget( ledtName, 1, 1, 1, 1 );
    lbl9 = new QLabel( widget );
    glay->addWidget( lbl9, 1, 2, 1, 1 );
    ledtQmin = new QLineEdit( widget );
    glay->addWidget( ledtQmin, 1, 3, 1, 1 );
    lbl16 = new QLabel( widget );
    glay->addWidget( lbl16, 1, 4, 1, 1 );
    ledtGbus = new QLineEdit( widget );
    glay->addWidget( ledtGbus, 1, 5, 1, 1 );
    lbl3 = new QLabel( widget );
    glay->addWidget( lbl3, 2, 0, 1, 1 );
    ledtUnom = new QLineEdit( widget );
    glay->addWidget( ledtUnom, 2, 1, 1, 1 );
    lbl10 = new QLabel( widget );
    glay->addWidget( lbl10, 2, 2, 1, 1 );
    ledtQmax = new QLineEdit( widget );
    glay->addWidget( ledtQmax, 2, 3, 1, 1 );
    lbl17 = new QLabel( widget );
    glay->addWidget( lbl17, 2, 4, 1, 1 );
    ledtBbus = new QLineEdit( widget );
    glay->addWidget( ledtBbus, 2, 5, 1, 1 );
    lbl4 = new QLabel( widget );
    glay->addWidget( lbl4, 3, 0, 1, 1 );
    ledtPh = new QLineEdit( widget );
    glay->addWidget( ledtPh, 3, 1, 1, 1 );
    cbChoosen = new QCheckBox( widget );
    glay->addWidget( cbChoosen, 3, 3, 1, 1 );
    lbl18 = new QLabel( widget );
    glay->addWidget( lbl18, 3, 4, 1, 1 );
    ledtPU = new QLineEdit( widget );
    glay->addWidget( ledtPU, 3, 5, 1, 1 );
    lbl5 = new QLabel( widget );
    glay->addWidget( lbl5, 4, 0, 1, 1 );
    ledtQh = new QLineEdit( widget );
    glay->addWidget( ledtQh, 4, 1, 1, 1 );
    lbl12 = new QLabel( widget );
    glay->addWidget( lbl12, 4, 2, 1, 1 );
    ledtPgmin = new QLineEdit( widget );
    glay->addWidget( ledtPgmin, 4, 3, 1, 1 );
    lbl19 = new QLabel( widget );
    glay->addWidget( lbl19, 4, 4, 1, 1 );
    ledtCX = new QLineEdit( widget );
    glay->addWidget( ledtCX, 4, 5, 1, 1 );
    lbl6 = new QLabel( widget );
    glay->addWidget( lbl6, 5, 0, 1, 1 );
    ledtPgen = new QLineEdit( widget );
    glay->addWidget( ledtPgen, 5, 1, 1, 1 );
    lbl13 = new QLabel( widget );
    glay->addWidget( lbl13, 5, 2, 1, 1 );
    ledtPhmin = new QLineEdit( widget );
    glay->addWidget( ledtPhmin, 5, 3, 1, 1 );
    lbl20 = new QLabel( widget );
    glay->addWidget( lbl20, 5, 4, 1, 1 );
    ledtCX2 = new QLineEdit( widget );
    glay->addWidget( ledtCX2, 5, 5, 1, 1 );
    lbl7 = new QLabel( widget );
    glay->addWidget( lbl7, 6, 0, 1, 1 );
    ledtQgen = new QLineEdit( widget );
    glay->addWidget( ledtQgen, 6, 1, 1, 1 );
    lbl14 = new QLabel( widget );
    glay->addWidget( lbl14, 6, 2, 1, 1 );
    ledtUmin = new QLineEdit( widget );
    glay->addWidget( ledtUmin, 6, 3, 1, 1 );
    lbl21 = new QLabel( widget );
    glay->addWidget( lbl21, 6, 4, 1, 1 );
    ledtDX = new QLineEdit( widget );
    glay->addWidget( ledtDX, 6, 5, 1, 1 );
    lbl11 = new QLabel( widget );
    glay->addWidget( lbl11, 3, 2, 1, 1 );

    QObject::connect( buttonBox, SIGNAL( accepted() ), this, SLOT( accept() ) );
    QObject::connect( buttonBox, SIGNAL( rejected() ), this, SLOT( reject() ) );

    QMetaObject::connectSlotsByName(this);

    setWindowTitle(QApplication::translate("NodeParamDialog", "Node Parameters Dialog", 0, QApplication::UnicodeUTF8));
    groupBox->setTitle(QApplication::translate("NodeParamDialog", "Node Parameters", 0, QApplication::UnicodeUTF8));
    lbl1->setText(QApplication::translate("NodeParamDialog", "id:", 0, QApplication::UnicodeUTF8));
    lbl8->setText(QApplication::translate("NodeParamDialog", "Umod:", 0, QApplication::UnicodeUTF8));
    lbl15->setText(QApplication::translate("NodeParamDialog", "Umax:", 0, QApplication::UnicodeUTF8));
    lbl2->setText(QApplication::translate("NodeParamDialog", "Name:", 0, QApplication::UnicodeUTF8));
    lbl9->setText(QApplication::translate("NodeParamDialog", "Qmin:", 0, QApplication::UnicodeUTF8));
    lbl16->setText(QApplication::translate("NodeParamDialog", "Gbus:", 0, QApplication::UnicodeUTF8));
    lbl3->setText(QApplication::translate("NodeParamDialog", "Unom:", 0, QApplication::UnicodeUTF8));
    lbl10->setText(QApplication::translate("NodeParamDialog", "Qmax:", 0, QApplication::UnicodeUTF8));
    lbl17->setText(QApplication::translate("NodeParamDialog", "Bbus:", 0, QApplication::UnicodeUTF8));
    lbl4->setText(QApplication::translate("NodeParamDialog", "Ph:", 0, QApplication::UnicodeUTF8));
    lbl18->setText(QApplication::translate("NodeParamDialog", "PU:", 0, QApplication::UnicodeUTF8));
    lbl5->setText(QApplication::translate("NodeParamDialog", "Qh:", 0, QApplication::UnicodeUTF8));
    lbl12->setText(QApplication::translate("NodeParamDialog", "Pgmin:", 0, QApplication::UnicodeUTF8));
    lbl19->setText(QApplication::translate("NodeParamDialog", "CX:", 0, QApplication::UnicodeUTF8));
    lbl6->setText(QApplication::translate("NodeParamDialog", "Pgen:", 0, QApplication::UnicodeUTF8));
    lbl13->setText(QApplication::translate("NodeParamDialog", "Phmin:", 0, QApplication::UnicodeUTF8));
    lbl20->setText(QApplication::translate("NodeParamDialog", "CX2:", 0, QApplication::UnicodeUTF8));
    lbl7->setText(QApplication::translate("NodeParamDialog", "Qgen:", 0, QApplication::UnicodeUTF8));
    lbl14->setText(QApplication::translate("NodeParamDialog", "Umin:", 0, QApplication::UnicodeUTF8));
    lbl21->setText(QApplication::translate("NodeParamDialog", "DX:", 0, QApplication::UnicodeUTF8));
    lbl11->setText(QApplication::translate("NodeParamDialog", "Choosen", 0, QApplication::UnicodeUTF8));

    fillControls();
}

//-------------------------------------

int NodeParamDialog::Exec()
{
    int res = exec();
    if( res == QDialog::Accepted )
    {
        node->id = ledtID->text().toInt();
        node->name = ledtName->text();

        node->Unom = ledtUnom->text().toFloat();
        node->Ph = ledtPh->text().toFloat();
        node->Qh = ledtQh->text().toFloat();
        node->Pgen = ledtPgen->text().toFloat();
        node->Qgen = ledtQgen->text().toFloat();
        node->Umod = ledtUmod->text().toFloat();
        node->Qmin = ledtQmin->text().toFloat();
        node->Qmax = ledtQmax->text().toFloat();
        //node->Pgmin = ledtPgmin->text().toFloat();
        //node->Phmin = ledtPhmin->text().toFloat();
        node->Umin = ledtUmin->text().toFloat();
        node->Umax = ledtUmax->text().toFloat();
        node->Gbus = ledtGbus->text().toFloat();
        node->Bbus = ledtBbus->text().toFloat();

        node->isChoosen = cbChoosen->isChecked();

        //node->PU = ledtPU->text().toInt();
        node->CX = ledtCX->text().toInt();
        //node->CX2 = ledtCX2->text().toInt();
        //node->DX = ledtDX->text().toInt();

    }
    return res;
}

//-------------------------------------

void NodeParamDialog::fillControls()
{
    if( node )
    {
        QString s = node->name;
        ledtName->setText( s );
        ledtID->setText( QString::number( node->id ) );


        ledtUnom->setText( QString::number( node->Unom ) );
        ledtPh->setText( QString::number( node->Ph ) );
        ledtQh->setText( QString::number( node->Qh ) );
        ledtPgen->setText( QString::number( node->Pgen ) );
        ledtQgen->setText( QString::number( node->Qgen ) );
        ledtUmod->setText( QString::number( node->Umod ) );
        ledtQmin->setText( QString::number( node->Qmin ) );
        ledtQmax->setText( QString::number( node->Qmax ) );
        //ledtPgmin->setText( QString::number( node->Pgmin ) );
        //ledtPhmin->setText( QString::number( node->Phmin ) );
        ledtUmin->setText( QString::number( node->Umin ) );
        ledtUmax->setText( QString::number( node->Umax ) );
        ledtGbus->setText( QString::number( node->Gbus ) );
        ledtBbus->setText( QString::number( node->Bbus ) );

        cbChoosen->setChecked( node->isChoosen );

        //ledtPU->setText( QString::number( node->PU ) );
        ledtCX->setText( QString::number( node->CX ) );
        //ledtCX2->setText( QString::number( node->CX2 ) );
        //ledtDX->setText( QString::number( node->DX ) );
    }
}

//-------------------------------------








